﻿using ProjectFootball.MVC.Foundation.ResourceLibrary;

namespace System
{
    public static class _DateTimeExtensions
    {
        public static DateTime _StartOfDay(this DateTime dateValue)
        {
            return new DateTime(dateValue.Year, dateValue.Month, dateValue.Day);
        }

        public static DateTime _EndOfDay(this DateTime dateValue)
        {
            return _StartOfDay(dateValue).AddDays(1).AddMilliseconds(-1);
        }

        public static DateTime _StartOfMonth(this DateTime dateValue)
        {
            return new DateTime(dateValue.Year, dateValue.Month, 1);
        }

        public static DateTime _EndOfMonth(this DateTime dateValue)
        {
            return dateValue._StartOfMonth().AddMonths(1).AddDays(-1);
        }

        public static string _DayPrefix(this DateTime dateValue)
        {
            switch (dateValue.Day)
            {
                case 1:
                case 21:
                case 31:
                    return dateValue.Day.ToString() + "st";

                case 2:
                case 22:
                    return dateValue.Day.ToString() + "nd";

                case 3:
                case 23:
                    return dateValue.Day.ToString() + "rd";

                default:
                    return dateValue.Day.ToString() + "th";
            }
        }

        public static bool _IsBetween(this DateTime test, DateTime startDate, DateTime endDate)
        {
            return test >= startDate && test <= endDate;
        }

        public static string _ToDisplayString(this DateTime value)
        {
            if (value == _DateTime.LowDate)
                return "Unknown";

            if (value.Date > DateTime.Today)
                return string.Empty;

            return value.ToShortDateString();
        }
    }
}